using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ACME.Northwind.DataTransfer;
using System.Linq.Expressions;
using ACME.Northwind.Service.Interfaces;

namespace ACME.Northwind.Service.IOCExtensions
{
	/// <summary>
	/// This is an extension class for CustomerCustomerDemo DTO objects and lists
	/// </summary>
	public static partial class CustomerCustomerDemoExtension
	{
		#region RunSelect
		/// <summary>
		/// Select all objects from store.
		/// </summary>
		public static void RunSelect(this List<CustomerCustomerDemoDTO> list)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			list.AddRange(proxy.RunSelect());
		}
		#endregion

		#region RunSelect Paged

		/// <summary>
		/// Using the specified Where expression, execute a query against the database to return a paged result set.
		/// </summary>
		public static PagedQueryResults<CustomerCustomerDemoDTO> RunSelect(this List<CustomerCustomerDemoDTO> list, int page, int pageSize, bool ascending, string sortColumn, string linq)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			PagedQueryResults<CustomerCustomerDemoDTO> retval = proxy.RunSelect(page, pageSize, ascending, sortColumn, linq);
			if (retval.GridData != null)
				list.AddRange(retval.GridData);
			return retval;
		}

		#endregion

		#region RunSelect Paged

		/// <summary>
		/// Using the specified Where expression, execute a query against the database to return a result set.
		/// </summary>
		public static void RunSelect(this List<CustomerCustomerDemoDTO> list, string linq)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			list.AddRange(proxy.RunSelect(linq));
		}

		#endregion

		#region Persist

		/// <summary>
		/// Persists this object to store.
		/// </summary>
		public static void Persist(this CustomerCustomerDemoDTO customercustomerdemo)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			proxy.Persist(customercustomerdemo);
		}

		/// <summary>
		/// Persists this collection to store.
		/// </summary>
		public static void Persist(this List<CustomerCustomerDemoDTO> customercustomerdemoList)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			proxy.Persist(customercustomerdemoList);
		}

		#endregion

		#region CustomerCustomerDemo SelectUsingPK

		/// <summary>
		/// Select a single object from this collection by its primary key.
		/// </summary>
		public static bool SelectByPrimaryKey(this CustomerCustomerDemoDTO customercustomerdemo, string customerid, string customertypeid)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			ICustomerCustomerDemoService customercustomerdemoService = (ICustomerCustomerDemoService)proxy;
			var item = customercustomerdemoService.SelectByPrimaryKey(customerid, customertypeid);
			if (item == null) return false;
			CopyObject(item, customercustomerdemo);
			return true;
		}

		#endregion

		#region CustomerCustomerDemo Select By Foreign Key
		/// <summary>
		/// Get the related 'CustomerDemographic' DTO object
		/// </summary>
		public static CustomerDemographicDTO GetCustomerDemographic(this CustomerCustomerDemoDTO item)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			ICustomerCustomerDemoService service = (ICustomerCustomerDemoService)proxy;
			return service.GetCustomerDemographicItem(item);
		}

		/// <summary>
		/// Get the related 'Customer' DTO object
		/// </summary>
		public static CustomerDTO GetCustomer(this CustomerCustomerDemoDTO item)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			ICustomerCustomerDemoService service = (ICustomerCustomerDemoService)proxy;
			return service.GetCustomerItem(item);
		}


		#endregion

		#region Delete

		/// <summary>
		/// Delete a single object.
		/// </summary>
		public static void Delete(this CustomerCustomerDemoDTO customercustomerdemo)
		{
			var proxy = ProxyFactory<CustomerCustomerDemoDTO>.GetProxy();
			ICustomerCustomerDemoService customercustomerdemoService = (ICustomerCustomerDemoService)proxy;
			customercustomerdemoService.Delete(customercustomerdemo);
		}

		#endregion

		/// <summary>
		/// Clones one DTO to another.
		/// </summary>
		internal static void CopyObject(CustomerCustomerDemoDTO source, CustomerCustomerDemoDTO destination)
		{
			destination.CustomerTypeId = source.CustomerTypeId;
			destination.CustomerId = source.CustomerId;
		}

	}
}
